package com.sc.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.sc.common.pojo.CommonResult;
import com.sc.common.pojo.EasyUiDataGridResult;
import com.sc.common.pojo.EasyUiTreeNode;
import com.sc.common.utils.HttpClientUtil;
import com.sc.pojo.TbContent;
import com.sc.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * Created by sc on 2017/10/19.
 */
@Controller
@RequestMapping("/content")
public class ContentController {
    @Autowired
    private ContentService contentService;

    @Value("${REST_BASE_URL}")
    private String REST_BASE_URL;
    @Value("${SYC_REDIS_URL}")
    String SYC_REDIS_URL;


    @RequestMapping("/query/list")
    @ResponseBody
    public EasyUiDataGridResult getList(Long categoryId,
                                        @RequestParam(value = "page",defaultValue = "1") Integer page,
                                        @RequestParam(value = "rows",defaultValue = "20") Integer rows){
           return contentService.getList(categoryId,page,rows);
    }


    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ResponseBody
    public CommonResult save(TbContent tbContent){
        CommonResult commonResult = contentService.save(tbContent);
        HttpClientUtil.doGet(REST_BASE_URL+SYC_REDIS_URL+tbContent.getCategoryId());
        return commonResult;
    }

    @RequestMapping(value = "/delete")
    @ResponseBody
    public CommonResult update(String ids){

        return contentService.delete(ids);
    }

}
